package card

//花色
const (
	flowerNIL int = iota	//留空
	flowerHEITAO			//黑桃
	flowerHONGTAO			//红桃
	flowerMEIHUA			//梅花
	flowerFANGKUAI			//方块
)

//点数
const (
	cardPointNIL int = iota
	cardPoint2  //1
	cardPoint3  //2
	cardPoint4  //3
	cardPoint5  //4
	cardPoint6  //5
	cardPoint7  //6
	cardPoint8  //7
	cardPoint9  //8
	cardPointT  //9
	cardPointJ  //10
	cardPointQ  //11
	cardPointK  //12
	cardPointA  //13
)

//定义所有扑克牌的牌值是 1 - 54 正好对应54张牌, 这样每张牌都有自己的牌值,花色,点数

type TCard struct {
	nValue int //牌值
	nFlower int //点数
	nPoint int //花色
}
// NewCard 新建卡牌
func NewCard(nValue int) *TCard{
	p := &TCard{}
	p.nValue = nValue
	p.nFlower = toFlower(nValue)
	p.nPoint = toCardValue(nValue)
	return p
}

// 从牌值获取花色
func toFlower(nValue int) int{
	if nValue <= 0 || nValue > 52{
		return flowerNIL
	}
	return ((nValue - 1) / 13) + 1
}

// 从牌值获取花色
func toFlowers(nValues []int) []int{
	var flower []int
	for _, num := range nValues {
		flower = append(flower, toFlower(num))
	}
	return flower
}


// 从牌值获取点数
func toCardValue (nValue int) int{
	if nValue <= 0 || nValue > 52 {
		return cardPointNIL
	}
	return ((nValue - 1) % 13) +1
}

func toCardValues(nValues []int) []int{
	var point []int
	for _, num := range nValues {
		point = append(point, toCardValue(num))
	}
	return point
}

// 转换成字符串
func (self *TCard) tostr() string {
	strResult := ""
	// 花色
	switch self.nFlower {
	case flowerHEITAO:
		{
			strResult = "♠"
		}
	case flowerHONGTAO:
		{
			strResult = "♥"
		}
	case flowerMEIHUA:
		{
			strResult = "♣"
		}
	case flowerFANGKUAI:
		{
			strResult = "♦"
		}
	}

	// 点数
	switch self.nPoint {
	case cardPoint3:
		{
			strResult = strResult + "3"
		}
	case cardPoint4:
		{
			strResult = strResult + "4"
		}
	case cardPoint5:
		{
			strResult = strResult + "5"
		}
	case cardPoint6:
		{
			strResult = strResult + "6"
		}
	case cardPoint7:
		{
			strResult = strResult + "7"
		}
	case cardPoint8:
		{
			strResult = strResult + "8"
		}
	case cardPoint9:
		{
			strResult = strResult + "9"
		}
	case cardPointT:
		{
			strResult = strResult + "T"
		}
	case cardPointJ:
		{
			strResult = strResult + "J"
		}
	case cardPointQ:
		{
			strResult = strResult + "Q"
		}
	case cardPointK:
		{
			strResult = strResult + "K"
		}
	case cardPointA:
		{
			strResult = strResult + "A"
		}
	case cardPoint2:
		{
			strResult = strResult + "2"
		}
		//case cardPointX:
		//	{
		//		strResult = "小王"
		//	}
		//case cardPointY:
		//	{
		//		strResult = "大王"
		//	}
	}

	return strResult
}



func (self *TCard) getValue() int{
	if self != nil {
		return self.nValue
	}
	return 0
}